package class71To80;

import java.io.*;
import java.util.Arrays;

public class BoundedKnapsack {
    public static int MAX_M = 40005;

    public static int MAX_N = 105;

    public static int n, t;


    public static int[] values = new int[MAX_N];

    public static int[] dp = new int[MAX_M];

    public static int[] weights = new int[MAX_N];

    public static int[] cnt = new int[MAX_N];


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            in.nextToken();
            t = (int) in.nval;
            for (int i = 1; i <= n; i++) {
                in.nextToken();
                values[i] = (int) in.nval;
                in.nextToken();
                weights[i] = (int) in.nval;
                in.nextToken();
                cnt[i] = (int) in.nval;
            }
            out.println(solve2());
        }
        out.flush();
        out.close();
        br.close();
    }

    // 普通不做优化 时间复杂度O(n * t * 每种商品的平均个数)
    public static int solve1() {
        int[][] dp = new int[n + 1][t + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= t; j++) {
                dp[i][j] = dp[i - 1][j];
                for (int k = 1; k <= cnt[i] && j >= k * weights[i]; k++) {
                    dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - k * weights[i]] + k * values[i]);
                }
            }
        }
        return dp[n][t];
    }

    // 空间压缩
    // 因为没有优化枚举
    // 时间复杂度依然是O(n * t * 每种商品的平均个数)
    public static int solve2() {
        Arrays.fill(dp, 0, t + 1, 0);
        for (int i = 1; i <= n; i++) {
            for (int j = t; j >= 0; j--) {
                for (int k = 1; k <= cnt[i] && j >= k * weights[i]; k++) {
                    dp[j] = Math.max(dp[j], dp[j - k * weights[i]] + k * values[i]);
                }
            }
        }
        return dp[t];
    }
}
